"""
    create by IAmFiveHigh on 2023/9/7
"""
import typing


class ListNode:
    def __init__(self, val: typing.Any):
        self.val = val
        self.next = None

    @classmethod
    def init_with_list(cls, l: list) -> typing.Optional['ListNode']:
        size = len(l)
        if size != 0:
            head = ListNode(l[0])
            cur = head
            for i in range(1, size):
                cur.next = ListNode(l[i])
                cur = cur.next
            return head
        else:
            return None

    def __str__(self):
        description = f"Node: {str(self.val)}"
        cur = self.next
        while cur is not None:
            description += f" -> Node: {str(cur.val)}"
            cur = cur.next
        return description
